4
תגובות
<form method="post" enctype="multipart/form-data">
<input type="file" name="upfile" />
<input type="submit" value="Upload me" />
</form>
<?php
if(isset($_FILES['upfile']))
{
$allowed = array('image/png', 'image/jpeg', 'image/gif');
$maxsize = 12 * 1024 * 1024; // 1mb
echo 'File ', $_FILES['upfile']['name'], ' was uploaded <br/>';
if( $_FILES['upfile']['error'] > 0)
die("Error #".$_FILES['upfile']['error']." occured");
echo 'It\'s type is: ', $_FILES['upfile']['type'], '<br/>';
if( !in_array($_FILES['upfile']['type'], $allowed) )
die('This type is not allowed');
$size_in_mb = $size_in_mb = round( $_FILES['upfile']['size']/1024/1024 ,3);
echo 'It\'s size is: ', $size_in_mb , 'mb <br/>';
if($size_in_mb > $maxsize)
die("The file is bigger then allowed");
echo 'The file passed all validations. <br/>
It has a proper size, it is an image and it had no errors. <br/>';
move_uploaded_file($_FILES['upfile']['tmp_name'], 'static/images/uploads/'.date("dmYHis").'.png');
}
<input type="file" name="upfile" />
<input type="submit" value="Upload me" />
</form>
<?php
if(isset($_FILES['upfile']))
{
$allowed = array('image/png', 'image/jpeg', 'image/gif');
$maxsize = 12 * 1024 * 1024; // 1mb
echo 'File ', $_FILES['upfile']['name'], ' was uploaded <br/>';
if( $_FILES['upfile']['error'] > 0)
die("Error #".$_FILES['upfile']['error']." occured");
echo 'It\'s type is: ', $_FILES['upfile']['type'], '<br/>';
if( !in_array($_FILES['upfile']['type'], $allowed) )
die('This type is not allowed');
$size_in_mb = $size_in_mb = round( $_FILES['upfile']['size']/1024/1024 ,3);
echo 'It\'s size is: ', $size_in_mb , 'mb <br/>';
if($size_in_mb > $maxsize)
die("The file is bigger then allowed");
echo 'The file passed all validations. <br/>
It has a proper size, it is an image and it had no errors. <br/>';
move_uploaded_file($_FILES['upfile']['tmp_name'], 'static/images/uploads/'.date("dmYHis").'.png');
}
גם אם אני לוחץ UPLOAD ולא מילאתי כלום אז הפונקציה בפנים פועלת..
4 תשובות
print_r($_FILES);
תראה מה יש במערך בכל אחד מהמקרים ותשנה את התנאי בהתאם.
ענה
יוווווווווואו
ב
20 לינואר 2012
#
זה מה שיש כשאני סתם לוחץ אפלוד:
Array ( [upfile] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )
וזה כשירפתי תמונה:
Array ( [upfile] => Array ( [name] => cpp.jpg [type] => image/jpeg [tmp_name] => C:\wamp\tmp\phpA01.tmp [error] => 0 [size] => 114124 ) )
ענה
יוווווווווואו
ב
20 לינואר 2012
#
מה להוסיף לתנאי?
ענה
יוווווווווואו
ב
20 לינואר 2012
#
הפרדתי את שני התנאים אז עכשיו זה פועל
if(isset($_FILES['upfile']['name']))
{
if($_FILES['upfile']['name']!="")
{
{
if($_FILES['upfile']['name']!="")
{